#include "LMContext.h"
#include <sstream>
#include <iomanip>
#include <boost/uuid/sha1.hpp>

LMContext::LMContext(void)
	: _user("shadowzyq.RIC_1")
	, _password("x")
	, _poolIp("ypool.net")
	, _poolPort(8086)
	, _threadNum(1)
	, _minerStartTime(boost::posix_time::microsec_clock::universal_time())
	, uniqueMerkleSeedGenerator(0)
	, miningStartTime(0)
{
	minerVersionString = "xptMiner 1.7c";

	totalCollisionCount = 0;
	totalShareCount = 0;
	totalRejectedShareCount = 0;
	total2ChainCount = 0;
	total3ChainCount = 0;
	total4ChainCount = 0;
	totalSieveCount = 0;

	memset(&workDataSource, 0, sizeof(workDataSource));

	InitializeCriticalSection(&workDataSource.cs_work);
	InitializeCriticalSection(&cs_xptClient);

	for(int i = 0; i < 32; ++i)
	{
		algorithmInited[i] = 0;
	}

	workerAccepterPort = 8888;
	developerFeeCount = 0;
}


LMContext::~LMContext(void)
{
}

std::string LMContext::PasswordSha1()
{
	std::string password_sha1;
	boost::uuids::detail::sha1 sha;
	sha.process_bytes(_password.c_str(), _password.size());
	unsigned int digest[5];
	sha.get_digest(digest);
	std::stringstream ss;
	ss << std::setw(5) << std::setfill('0') << std::hex << (digest[0] ^ digest[1] ^ digest[4]) << (digest[2] ^ digest[3] ^ digest[4]);
	password_sha1 = ss.str();
	
	return password_sha1;
}

void LMContext::resetMinerStartTime()
{
	_minerStartTime = boost::posix_time::microsec_clock::universal_time();
}

boost::posix_time::ptime LMContext::minerStartTime()
{
	return _minerStartTime;
}
